package com.mijie.homi.admin.web.user;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.mijie.homi.admin.service.user.ThirdPartAccountService;
import com.mijie.homi.common.domain.user.ThirdPartAccount;
import com.mijie.homi.common.domain.user.ThirdPartOfficialAccount;
import com.mijie.util.IOUtil;

@Controller
@RequestMapping("/user/thirdpart")
public class ThirdPartController {

	@Autowired
	private ThirdPartAccountService service;
	
	@RequestMapping("/list")
	public String list(Model model){
		List<ThirdPartOfficialAccount>  list = service.listThirdPartOfficialAccount();
		model.addAttribute("list", list);
		return "user/thirdpart/list";
	}
	
	@RequestMapping("/delete")
	public String delete(int type){
		service.deleteThirdPartOfficialAccount(type);
		return "redirect:/user/thirdpart/list.shtml";
	}
	
	@RequestMapping("/edit")
	public String edit(Model model,int type){
		ThirdPartOfficialAccount account = service.getThirdPartOfficialAccount(type);
		model.addAttribute("account", account);
		return "user/thirdpart/edit";
	}
	
	@RequestMapping("/create")
	public String create(){
		return "user/thirdpart/create";
	}
	
	@RequestMapping("/save")
	public void save(ThirdPartOfficialAccount account,HttpServletResponse response) throws IOException{
		service.addThirdPartOfficialAccount(account);
		IOUtil.write(response, "保存成功");
	}
}
